<template>
	<view class="merchant-card" @click="handleClick">
		<view class="merchant-logo">
			<image class="merchant-avatar" mode="aspectFill" :src="logo" />
		</view>
		<view class="merchant-info">
			<view class="merchant-details">
				<view class="merchant-name">
					{{ name }}
					<text class="merchant-type" v-if="isOfficial">官方旗舰店</text>
				</view>
				<view class="merchant-rating">
					<view class="merchant-stars">
						<uni-icons v-for="n in 5" :key="n" type="star-filled" size="14"
							:color="n <= Math.floor(rating) ? '#ffcc00' : (n === Math.ceil(rating) && rating % 1 > 0 ? '#ffcc00' : '#eee')"></uni-icons>
					</view>
					<text>{{ rating.toFixed(1) }}</text>
					<text class="merchant-order-count">已售{{ sales }}+</text>
				</view>
				<view class="merchant-tags">
					<text class="merchant-tag" v-for="tag in tags" :key="tag">{{ tag }}</text>
				</view>
				<view class="merchant-promotion" v-for="promo in promotions" :key="promo">
					<uni-icons type="tag" size="14" color="#ff6a6a"></uni-icons>
					<text>{{ promo }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	name: 'merchant-card';
	const props = defineProps({
		logo: {
			type: String,
			required: true
		},
		name: {
			type: String,
			required: true
		},
		isOfficial: {
			type: Boolean,
			default: false
		},
		rating: {
			type: Number,
			default: 0
		},
		sales: {
			type: Number,
			default: 0
		},
		tags: {
			type: Array,
			default: () => []
		},
		promotions: {
			type: Array,
			default: () => []
		}
	});

	const emit = defineEmits(['click']);

	const handleClick = () => {
		emit('click');
	};
</script>

<style lang="scss" scoped>
	.merchant-card {
		padding: 5px;
		background-color: #fff;
		border-radius: 8px;
		overflow: hidden;
		margin-bottom: 15px;
		box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
		display: flex;

		.merchant-avatar {
			width: 60px;
			height: 60px;
			border-radius: 8px;
			border: 1px solid #eee;
			background-color: #fff;
		}

		.merchant-info {
			padding: 0 5px;
			flex: 1;

			.merchant-name {
				font-size: 16px;
				font-weight: bold;
				margin-bottom: 5px;

				.merchant-type {
					font-size: 11px;
					padding: 2px 6px;
					background-color: #ff6a6a;
					border-radius: 3px;
					color: white;
					margin-left: 8px;
				}
			}

			.merchant-rating {
				display: flex;
				align-items: center;
				margin-bottom: 5px;
				font-size: 13px;

				.merchant-stars {
					display: flex;
					margin-right: 5px;
				}

				.merchant-order-count {
					color: #999;
					margin-left: 10px;
				}
			}

			.merchant-tags {
				display: flex;
				flex-wrap: wrap;
				gap: 5px;
				margin-bottom: 8px;

				.merchant-tag {
					font-size: 11px;
					padding: 2px 6px;
					background-color: #f5f5f5;
					border-radius: 3px;
					color: #666;
				}
			}

			.merchant-promotion {
				display: flex;
				align-items: center;
				font-size: 12px;
				color: #ff6a6a;
				margin-bottom: 5px;
			}
		}
	}
</style>